package com.brokendust.client.config.module.item;

import com.brokendust.client.config.module.ComponentJson;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.crash.ReportedException;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.JsonToNBT;

public class ItemShowJson implements ComponentJson {
    public String type;
    private String object_name;
    private String item;
    private float scale;
    private int position;
    private int x;
    private int y;

    public ItemShowJson() {
        this.type = "Item";
        this.object_name = "";
        this.item = "";
    }

    public static ItemShowJson readJSON(String string) {
        GsonBuilder builder = new GsonBuilder();
        Gson gson = builder.create();
        return gson.fromJson(string, ItemShowJson.class);
    }

    public ItemStack getItemStack() {
        ItemStack itemStack = null;
        try {
            CompoundNBT compound = JsonToNBT.parseTag(this.item);
            itemStack = ItemStack.of(compound);
        } catch (CommandSyntaxException | ReportedException e) {
            e.printStackTrace();
        }
        return itemStack;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getObject_name() {
        return this.object_name;
    }

    public void setObject_name(String object_name) {
        this.object_name = object_name;
    }

    public String getItem() {
        return this.item;
    }

    public void setItem(String item) {
        this.item = item;
    }

    public int getPosition() {
        return this.position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public int getX() {
        return this.x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return this.y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public float getScale() {
        return this.scale;
    }

    public void setScale(float scale) {
        this.scale = scale;
    }
}
